import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase="DBshop010_处理退货"

firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_link_text("点此申请退货").click()

orderId=readFile(get_pro_rootpath()+'\public\order003.txt')
firefox.find_element_by_name("order_sn").send_keys(orderId)
firefox.find_element_by_id("search-order").click()
time.sleep(2)
firefox.find_element_by_id("refund_info").send_keys("111")
firefox.find_element_by_xpath("//button[text()='申请退货']").click()
time.sleep(3)
firefox.switch_to_alert().accept()
time.sleep(3)
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"销售管理","退货管理")
firefox.find_element_by_name("order_sn").send_keys(orderId)
firefox.find_element_by_xpath("//button").click()
firefox.find_element_by_link_text("处理退货").click()

from selenium.webdriver.support.select import Select
s=Select(firefox.find_element_by_id("refund_state"))
s.select_by_visible_text("同意退货")
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys("2199")
firefox.find_element_by_id("re_refund_info").send_keys("同意")

firefox.find_element_by_xpath("//button").click()


firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()


firefox.find_element_by_xpath("//button").click

firefox.find_element_by_name("search_content").send_keys(orderId)
firefox.find_element_by_xpath("//button[text()='搜索']").click()

try:
    if firefox.find_element_by_xpath("//table/tbody/tr/td[4]").text=='退款成功':
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
